package jmine.tec.web.wicket.application;

import jmine.tec.utils.debug.impl.DebugRuntimeFactory;
import jmine.tec.web.wicket.upperCase.UpperCaseBeforeRenderListener;

import org.apache.wicket.Application;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.util.time.Duration;

/**
 * @author takeshi
 */
public abstract class JMineWicketWebApplication extends WebApplication {

    private boolean upperCase;

    /**
     * @return the upperCase
     */
    public boolean isUpperCase() {
        return this.upperCase;
    }

    /**
     * @param upperCase the upperCase to set
     */
    public void setUpperCase(boolean upperCase) {
        this.upperCase = upperCase;
    }

    /**
     * {@inheritDoc}
     * 
     * @see org.apache.wicket.protocol.http.WebApplication#getConfigurationType()
     */
    @Override
    public String getConfigurationType() {
        String config = super.getConfigurationType();
        if (Application.DEVELOPMENT.equals(config)) {
            return DebugRuntimeFactory.ENABLED ? Application.DEVELOPMENT : Application.DEPLOYMENT;
        }
        return config;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void init() {
        if (DebugRuntimeFactory.ENABLED) {
            this.getResourceSettings().setResourcePollFrequency(Duration.seconds(1));
        }

        if (this.upperCase) {
            this.addPreComponentOnBeforeRenderListener(new UpperCaseBeforeRenderListener());
        }
    }
}
